package com.jiangyg.mall.member.controller;

import com.jiangyg.mall.core.support.restful.Pagination;
import com.jiangyg.mall.core.support.restful.Result;
import com.jiangyg.mall.member.dto.MemberCollectSubjectDTO;
import com.jiangyg.mall.member.service.MemberCollectSubjectService;
import com.jiangyg.mall.member.vo.MemberCollectSubjectVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 类描述：会员收藏的专题活动控制器
 *
 * @author jiangyg
 * @version email@jiangyg.com
 * @date 2021-10-30 07:33:09
 */
@RestController
@RequestMapping("/member/memberCollectSubject")
public class MemberCollectSubjectController {

    /**
     * 会员收藏的专题活动接口
     */
    private final MemberCollectSubjectService memberCollectSubjectService;

    @Autowired
    public MemberCollectSubjectController(MemberCollectSubjectService memberCollectSubjectService) {
        this.memberCollectSubjectService = memberCollectSubjectService;
    }

    /**
     * 功能描述：会员收藏的专题活动分页查询
     *
     * @param request    请求
     * @param pagination 分页参数
     * @return 返回分页会员收藏的专题活动
     */
    @ResponseBody
    @PostMapping("/select")
    public Result<Pagination<MemberCollectSubjectVO>> select(HttpServletRequest request, @RequestBody Pagination<MemberCollectSubjectVO> pagination) throws Exception {
        return Result.ok(memberCollectSubjectService.selectPagination(pagination));
    }

    /**
     * 功能描述：保存或者修改会员收藏的专题活动
     *
     * @param request 请求
     * @param dto     会员收藏的专题活动
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/save")
    public Result<Object> save(HttpServletRequest request, @RequestBody @Validated MemberCollectSubjectDTO dto) throws Exception {
        return Result.saveOrUpdate(memberCollectSubjectService.saveOrUpdate(dto));
    }

    /**
     * 功能描述：根据ID获取会员收藏的专题活动
     *
     * @param request 请求
     * @param memberCollectSubjectId  会员收藏的专题活动ID
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/info")
    public Result<MemberCollectSubjectVO> info(HttpServletRequest request, @RequestParam(name = "memberCollectSubjectId") Long memberCollectSubjectId) throws Exception {
        return Result.ok(memberCollectSubjectService.selectById(memberCollectSubjectId));
    }

    /**
     * 功能描述：删除会员收藏的专题活动
     *
     * @param request 请求
     * @param memberCollectSubjectIds 批量删除的会员收藏的专题活动ID
     * @return 结果
     */
    @ResponseBody
    @PostMapping("/delete")
    public Result<Object> delete(HttpServletRequest request, @RequestParam(name = "memberCollectSubjectIds") List<Long> memberCollectSubjectIds) {
        return Result.delete(memberCollectSubjectService.delete(memberCollectSubjectIds));
    }

}
